<?php

namespace common\models;

use app\models\AdminLog;
use Yii;

/**
 * This is the model class for table "config".
 *
 * @property string $id
 * @property string $variable
 * @property string $value
 * @property string $name
 * @property string $scode
 * @property string $type
 * @property string $type_data
 */
class Config extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'config';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['variable', 'name', 'scode'], 'required'],
            [['value', 'type', 'type_data'], 'string'],
            [['variable', 'name', 'scode'], 'string', 'max' => 64],
            [['variable'], 'unique'],
            ['type', 'in', 'range' => ['input', 'select', 'file', 'checkbox', 'textarea', 'radio']]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'variable' => '变量名',
            'value' => '变量值',
            'name' => '名称',
            'scode' => '范围',
            'type' => '编辑类型',
            'type_data' => '对应type的数据源',
        ];
    }

    public function afterDelete()
    {
        parent::afterDelete();
        AdminLog::log("删除配置：" . $this->name, "delete");
    }
}
